<?php

namespace app\common\model\imchat;

use think\Model;
use think\facade\Db;

class Friends extends Model
{
    // 表名
    protected $name = 'imchat_friends';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    protected $append = [
        'create_time_text',
    ];

    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'to_uid', 'id', [], 'LEFT');
    }
}
